package com.dmxh.aop;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class AopLog {

    @Pointcut(value = "execution(public * com.dmxh.service.impl.*.*(..)) || @annotation(com.dmxh.aop.An)")
    public void pointCut(){}

    @Before("pointCut()")
    public void beforePoint(JoinPoint joinPoint) {
        //获取方法参数
        Object[] args = joinPoint.getArgs();
        //获取方法名
        Signature signature = joinPoint.getSignature();
        log.info("方法名为{},参数为{}"+signature,args);
    }

    @AfterReturning(value = "pointCut()",returning = "result")
    public void afterReturn(Object result) {
        log.info("返回的结果为" + JSON.toJSONString(result));
    }



}
